package com.binhthuan.catechist.client.menu;

import com.binhthuan.catechist.client.ContentFactory;
import com.smartgwt.client.widgets.tree.TreeNode;

public class StackMenuItem extends TreeNode {

    public static final String DEFAULT_ICON = "icons/16/default-menu-icon.png";
    public static final String HISTORYTOKEN_PROPERTY = "historyToken";
    public static final String FACTORY_PROPERTY = "factory";

    public StackMenuItem() {
        super();
    }

    public StackMenuItem(String name) {
        super(name);
    }

    public StackMenuItem(ContentFactory contentFactory) {
        this(contentFactory.getID(), contentFactory);
    }

    public StackMenuItem(String name, String icon) {
        super(name);
        if (icon != null) {
            setIcon(icon);
        }
    }

    public StackMenuItem(String name, String title, String icon) {
        super(name);
        if (title != null) {
           setTitle(title); 
        }

        if (icon != null) {
            setIcon(icon);
        }
    }

    public StackMenuItem(String name, ContentFactory factory) {
        super(name);
        if(factory != null) {
            setTitle(factory.getTitle());
            setIcon(factory.getIcon());
            setHistoryToken(factory.getID());
            setFactory(factory);
        }
    }

    public StackMenuItem(String name, String icon, ContentFactory factory) {
        this(name, icon);
        if (factory != null) {
            setTitle(factory.getTitle());
            setFactory(factory);
            setHistoryToken(factory.getID());
        }
    }

    public StackMenuItem(String name, String icon, ContentFactory factory, String historyToken) {
        this(name, icon, factory);
        setHistoryToken(historyToken);
    }

    public void setHistoryToken(String token) {
        setAttribute(HISTORYTOKEN_PROPERTY, token);
    }

    public String getHistoryToken() {
        return getAttributeAsString(HISTORYTOKEN_PROPERTY);
    }
    
    public void setFactory(ContentFactory factory) {
        setAttribute(FACTORY_PROPERTY, factory);
    }
    
    public ContentFactory getFactory() {
        return (ContentFactory) getAttributeAsObject(FACTORY_PROPERTY);
    }
}
